//
//  ActivityDetailVc.m
//  MJApp
//
//  Created by John on 15/5/17.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "ActivityDetailVc.h"
#import "ActivityDetailCell.h"
#import "ShareModel.h"
#import "JoinUserViewController.h"
#import "DynamicSendViewController.h"
#import "MineInfoNewViewController.h"

@interface ActivityDetailVc ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,ActivityDetailCellDelegate,UMSocialUIDelegate>
@property (nonatomic, copy) NSString * ID;
@property (nonatomic, strong) NSDictionary * infoDic;
@property (nonatomic, strong) NSDictionary * activityDic;//传入的的活动信息
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ActivityDetailVc

-(id)initWithDic:(NSDictionary *)activityDic{
    
    if (self = [super init]) {
        self.activityDic = activityDic;
        self.ID = activityDic[@"id"];
    }
    return self;

}
//- (void)viewWillAppear:(BOOL)animated {
//    
//    [((TabBarController *)self.tabBarController) setTabbarHidden:YES];
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = self.activityDic[@"title"];
    [self getActivityDeataiIsLoadMore:NO];
    [self.rightBtn setImage:[UIImage imageNamed:@"hd_031"] forState:UIControlStateNormal];
    // Do any additional setup after loading the view from its nib.
}

- (void)clickRightButton {
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"text"] = [NSString stringWithFormat:@"#%@#,%@",self.infoDic[@"detail"][@"title"],self.infoDic[@"detail"][@"content"]];
    UIImageView *shareImageView = [[UIImageView alloc] init];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kUrl,self.infoDic[@"detail"][@"back_img"]]];
    [shareImageView sd_setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        shareImageView.image = image;
        dic[@"image"] = image;
        [ShareModel shareModelWithObject:self withDic:dic];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return tableView.bounds.size.height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    ActivityDetailCell * cell = [ActivityDetailCell cellForTableview:tableView];
    cell.infoDic = self.infoDic;
    cell.delegate = self;
    return cell;
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 0;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 0;
}

- (void)getActivityDeataiIsLoadMore:(BOOL)isLoadMore{
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"id"] = self.ID;
    [WLHTTPRequest getActivityDetailWithParam:param usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        self.infoDic =resultDictionary[@"data"];
        [self.tableView reloadData];
        
    } andFailureBlock:^(NSError *resultError) {
        
    }];
}
- (void)joinActivityWithActivtyDic:(NSDictionary *)activityDic{

    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"id"] = activityDic[@"detail"][@"id"];
    param[@"user_id"] = [userInfoTool share].ID;
   [WLHTTPRequest joinInActivityWithParam:param usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
       if ([resultDictionary[@"status"] intValue]==1) {
           [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"恭喜，参加活动成功"];
       }else{
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:resultDictionary[@"msg"]];
           
       }
   } andFailureBlock:^(NSError *resultError) {
       
   }];
}

- (void)joinUserList:(NSArray *)listArray {
    
    JoinUserViewController *joinUserVC = [[JoinUserViewController alloc] initWithArray:listArray];
    [self.navigationController pushViewController:joinUserVC animated:YES];
}

#pragma mark share回调
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response {
    
    if (response.responseCode == UMSResponseCodeSuccess) {
    
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        dic[@"user_id"] = [userInfoTool share].ID ? [userInfoTool share].ID : @"0";
        dic[@"id"] = self.infoDic[@"detail"][@"id"];
        dic[@"type"] = @"1";
        dic[@"plate"] = @"4";
        [WLHttpRequestAfter usercallBackShareWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
            
        } andFailureBlock:^(NSError *resultError) {
            
        }];
    }
}


- (void)commentActivityWithActivtyDic:(NSDictionary *)activityDic {
    
    [self.navigationController pushViewController:[[DynamicSendViewController alloc] init] animated:YES];
}

- (void)checkUserInfo:(NSDictionary *)dic {
    
    MineInfoNewViewController *infoVC = [[MineInfoNewViewController alloc] initWithID:dic[@"id"]];
    infoVC.title = [NSString stringWithFormat:@"\"%@\"个人中心",dic[@"nick_name"]];
    [self.navigationController pushViewController:infoVC animated:YES];
    
}

@end

